package com.yu.mall.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class ParamFilter implements Filter {

    private FilterConfig filterConfig;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws
            IOException, ServletException {
        String path = ((HttpServletRequest) servletRequest).getRequestURI();
        if(path.startsWith("/swagger-ui") || path.startsWith("/v2") || path.startsWith("/websocket")){
            filterChain.doFilter(servletRequest,servletResponse);
        }else{
            filterChain.doFilter(new ParamHttpServletRequestWrapper((HttpServletRequest) servletRequest), servletResponse);
        }
    }

    @Override
    public void destroy() {
        this.filterConfig = null;
    }
}